{ext->aasort array=$data.aditionalelements.list args="+name" assign="data_list"}
{capture name="hidden"}
		<input name="admin" type="hidden" value="1">		
		<input name="mod" type="hidden" value="catalog">
		<input name="act" type="hidden" value="add_block">
		<input name="lang" type="hidden" value="{$smarty.session.lang}">
		<input name="parent" type="hidden" value="{$smarty.get.id}">
		<input name="name" type="hidden" value="{$smarty.get.name}">
{/capture}	
{capture name="fields"}
<!-- * -->
		<table width="100%" cellpadding="0" cellspacing="0">
			<tr>
				<td height="35"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>		
			</tr>
		</table>
		<table width="100%" cellpadding="3" cellspacing="0">
			<tr>
				<td width="35%" height="1"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>
				<td><img src="client/img/spacer.gif" class="spacer" alt="" /></td>					
			</tr>		
{literal}	
<script language="javascript1.4" type="text/javascript">	
	var aData = new Array();	
	var aBlocks = new Array();	
	function addTemplate (sTemplateName, sBlockType){
		var bAdd=new Boolean (true);
		var i=new Number(aData.length);		
		for (ii=0; ii<i; ii++) 	if (aData[ii][1]==sBlockType && aData[ii][0]==sTemplateName) bAdd=false;	
		if (bAdd==true) {
			aData[i]= new Array();
			aData[i][0]=sTemplateName;
			aData[i][1]=sBlockType;		
		}
	}
	function addBlock (nID, sType) {		
		aBlocks[nID]=sType;		
	}
	function changeType (nID, sTemplate){
		//alert(nID+' '+sTemplate);
		var z=new Number(aData.length);
		var oSelect=window.document.getElementById('templatelist');
		var nOptCounter=new Number(0);
		var nSelectedIndex=new Number();
		
		if (nID>0) oSelect.disabled=false;
		else oSelect.disabled=true;	
		
		for (i=0; i<oSelect.options.length; i++) {
			oSelect.options[i]=null;
		}		
		oSelect.value=null;
		
		for(i=0; i<z; i++){
			if(aData[i][1]==aBlocks[nID]) {
				if(aData[i][0]==sTemplate)nSelectedIndex=nOptCounter;
				oSelect.options[nOptCounter]=new Option(aData[i][0], aData[i][0], false, false);
				nOptCounter++;
			}
		}			
		oSelect.selectedIndex=nSelectedIndex;
		if (nOptCounter<1) oSelect.disabled=true;	
	}
</script>
{/literal}

<script language="javascript1.4" type="text/javascript">
{foreach from=$data_list item=types}	
	addBlock({$types.id},'{$types.type}');
	{foreach from=$types.templates item=temps}
		addTemplate ('{$temps}','{$types.type}');	
	{/foreach}
{/foreach}	
</script>	
			<tr>
				<td>{t t='Pavadinimas'}: <!-- [{$data.aditionalelements.curent.id} | {$data.aditionalelements.curent.template}] --></td>
				<td>
					<select name="id" style="border:1px solid #A8B3B8; width:100%;" onChange="changeType(this.value)">
						<option value="-1"{if $data.aditionalelements.curent.search_in_tree==1} selected="selected"{/if}>{t t='Paveldėti iš aukštesnio lygio'}</option>
						<option value="0"{if $data.aditionalelements.curent.id==0} selected="selected"{/if}>{t t='Tuščias'}</option>
					{foreach from=$data_list item="element"}					
					{if $smarty.get.type==-1 || $element.type==$smarty.get.type}
						<option value="{$element.id}" {if $data.aditionalelements.curent.id==$element.id && $data.aditionalelements.curent.search_in_tree==0} selected="selected"{/if}>{$element.name}</option>
					{/if}
					{/foreach}
					</select>
					{*debug var=$data.aditionalelements*}
				</td>
			</tr>				
			
			<tr>
				<td>{t t='Šablomas'}:</td>
				<td>
					{if $smarty.get.template!=-1}{t t="Šablono keitimas draudžiamas"}{/if}
					<select name="dlink{if $smarty.get.template!=-1}1{/if}" style="border:1px solid #A8B3B8; width:100%; {if $smarty.get.template!=-1}visibility:hidden; width:1px; height:1px;{/if}" id='templatelist' disabled ></select>					
					{if $smarty.get.template!=-1}<input type="hidden" name="dlink" value="{$smarty.get.template}">{/if}
				</td>
			</tr>	
				
		</table>	
		<table width="100%" cellpadding="0" cellspacing="0">
			<tr>
				<td height="35"><img src="client/img/spacer.gif" class="spacer" alt="" /></td>		
			</tr>
		</table>
<!-- /* -->
{if $data.aditionalelements.curent.id}
<script language="javascript1.4" type="text/javascript">
	changeType ({$data.aditionalelements.curent.id},'{$data.aditionalelements.curent.template}')
</script>
{/if}
{/capture}
